<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="entity.MaterialBean" %>
<%@ page import="dao.MaterialDao" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Collections" %>
<html>

<head>
    <meta charset="utf-8">
    <title>物料列表信息</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/list.css">
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/selectMultip.js"></script>
    <!-- Latest compiled and minified CSS -->
    <%--    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/css/bootstrap-select.min.css">--%>

    <%--    <!-- Latest compiled and minified JavaScript -->--%>
    <%--    <script src="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/js/bootstrap-select.min.js"></script>--%>

    <%--    <!-- (Optional) Latest compiled and minified JavaScript translation files -->--%>
    <%--    <script src="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/js/i18n/defaults-*.min.js"></script>--%>
</head>

<body>

<div class="container-fluid">
    <div class="row">

        <div class="col-sm-12" id="right">
            <ol class="breadcrumb">
                <li class="active">菜单
                </li>
                <li class="active">物料信息
                </li>
            </ol>
            <%
                int searchFlag=0;
                if(request.getAttribute("searchFlag")!=null)
                    searchFlag = (int)request.getAttribute("searchFlag");
                ArrayList<MaterialBean>materialBeanList=(ArrayList<MaterialBean>)request.getAttribute("list");
                String itemId=(String)request.getAttribute("itemId");
                String itemName=(String)request.getAttribute("itemName");
                ArrayList<String> itemClassesList=(ArrayList<String> )request.getAttribute("itemClassesList");
                String vendorName=(String)request.getAttribute("vendorName");
                String phoneNumber=(String)request.getAttribute("phoneNumber");
                int pageCount=(int)request.getAttribute("pageCount");
                int curpage=(int)request.getAttribute("curpage");
                System.out.println("material_list pageCount="+pageCount);
                System.out.println("material_list curpage="+curpage);
            %>
            <div class="panel panel-default">
                <div class="panel-heading">
                    搜索
                </div>
                <div class="panel-body">
                    <form role="form" class="form-inline" action="MaterialListServlet?searchFlag=1" method="post" accept-charset="UTF-8">
                        <div class="form-group">
                            <label>物料编号</label>
                            <input type="text" class="form-control custom-smaller-input" id="itemId"
                                   name="itemId" value="<%=searchFlag==1?itemId:""%>" placeholder="请输入物料编号">
                        </div>
                        <div class="form-group">
                            <label>物料名称</label>
                            <input type="text" class="form-control custom-smaller-input" id="itemName" name="itemName"
                                   value="<%=searchFlag==1?itemName:""%>" placeholder="请输入物料名称">
                        </div>
                        <div class="form-group">
                            <label>材料类型</label>
                            <select class="form-control" id="itemClasses" name="itemClasses" multip >
                                <option value="">---请选择---</option>
                                <option value="金属"<%=(itemClassesList.contains("金属")&&searchFlag==1)?"choose":""%>>金属</option>
                                <option value="合金"<%=(itemClassesList.contains("合金")&&searchFlag==1)?"choose":""%>>合金</option>
                                <option value="复合材料"<%=(itemClassesList.contains("复合材料")&&searchFlag==1)?"choose":""%>>复合材料</option>
                                <option value="其它"<%=(itemClassesList.contains("其它")&&searchFlag==1)?"choose":""%>>其它</option>
                            </select>


                        </div>

                        <div class="form-group">
                            <label>供应商</label>
                            <input type="text" class="form-control custom-smaller-input" id="vendorName"
                                   name="vendorName"
                                   value="<%=searchFlag==1?vendorName:""%>" placeholder="请输入供应商名称">
                        </div>
                        <div class="form-group">
                            <label>电话</label>
                            <input type="text" class="form-control custom-smaller-input" id="phoneNumber"
                                   name="phoneNumber" value="<%=searchFlag==1?phoneNumber:""%>" placeholder="请输入联系人电话">
                        </div>
                        <div class="form-group">
                            <button type="submit" class="searchButton btn btn-primary">搜索</button>
                        </div>
                        <div class="form-group">
                            <a class="addButton btn btn-default" href="MaterialEditServlet">添加</a>
                        </div>
                    </form>
                </div>
            </div>
            <!--
            列表展示
        -->
            <div class="table-responsive">
                <table class="table table-striped ">
                    <thead>
                    <tr>
                        <%--<th>序号</th>--%>
                        <th>物料编号</th>
                        <th>物料名称</th>
                        <th>材料类型</th>
                        <th>供应商名称</th>
                        <th>厂址</th>
                        <th>入库时间</th>
                        <th>联系人</th>
                        <th>手机号</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <%
                        for(int i=0;i<materialBeanList.size();i++) {
                    %>
                    <tr>
                        <td><%=materialBeanList.get(i).getItemId()%>
                        </td>
                        <td><%=materialBeanList.get(i).getItemName()%>
                        </td>
                        <td><%=materialBeanList.get(i).getItemClasses()%>
                        </td>
                        <td><%=materialBeanList.get(i).getVendorName()%>
                        </td>
                        <td><%=materialBeanList.get(i).getSite()%>
                        </td>
                        <td><%=materialBeanList.get(i).getInboundTime()%>
                        </td>
                        <td><%=materialBeanList.get(i).getContact()%>
                        </td>
                        <td><%=materialBeanList.get(i).getPhoneNumber()%>
                        </td>
                        <td>
                            <div class="btn-group">
                                <a class="reviseButton btn btn-default" href="MaterialEditServlet?id=<%=materialBeanList.get(i).getId()%>&pageCount=<%=pageCount%>&curpage=<%=curpage%>">修改</a>
                                <a class="deleteButton btn btn-danger"
                                   href="#" onclick="confirmDelete(<%=materialBeanList.get(i).getId()%>)">删除</a>
                            </div>
                        </td>
                    </tr>
                    <%
                        }
                    %>
                    </tbody>
                </table>
            </div>
            <ul class="pagination" style="float: right;">
                <li><span style="pointer-events: none">共<%=pageCount%>页</span></li>
                <li>
                    <a href="MaterialListServlet?alterpage=-1&page=<%=curpage%>&itemId=<%=itemId%>&itemName=<%=itemName%>&vendorName=<%=vendorName%>&phoneNumber=<%=phoneNumber%>">&laquo;</a>
                </li>
                <%
                    int psize = 5; //页面号码标签数量
                    int pageNumStart = psize * ((curpage - 1) / psize)+1;
                    int pageNumEnd = pageNumStart + psize - 1;
                    if(pageNumEnd>pageCount){
                        pageNumEnd=pageCount;
                    }
                    for (int i = pageNumStart ; i <= pageNumEnd; i++) {
                        if (i == curpage) {
                            out.println("<li class=\"active\"><a href=\"MaterialListServlet?page=" + i + "&itemId=" + itemId + "&itemName=" + itemName  + "&vendorName=" + vendorName + "&phoneNumber=" + phoneNumber + "\">" + i + "</a></li>");

                        } else {
                            out.println("<li><a href=\"MaterialListServlet?page=" + i + "&itemId=" + itemId + "&itemName=" + itemName  + "&vendorName=" + vendorName + "&phoneNumber=" + phoneNumber + "\">" + i + "</a></li>");
                        }
                    }
                %>
                <li>
                    <a href="MaterialListServlet?alterpage=1&&page=<%=curpage%>&itemId=<%=itemId%>&itemName=<%=itemName%>&vendorName=<%=vendorName%>&phoneNumber=<%=phoneNumber%>">&raquo;</a>
                </li>
            </ul>
        </div>
    </div>
</div>
<script>
    selectMultip.register()
    function confirmDelete(id) {
        if (confirm("确定要删除吗？")) {
            window.location.href = "MaterialDeleteServlet?id="+id+"&page=<%=curpage%>&itemId=<%=itemId%>&itemName=<%=itemName%>&vendorName=<%=vendorName%>&phoneNumber=<%=phoneNumber%>";
        }
    }
    $(function () {
        $('select').selectpicker();
    });
</script>
</body>

</html>